#ifndef LUSHANHU_H
#define LUSHANHU_H

#include <QWidget>
#include <QGraphicsScene>
#include <QGraphicsPixmapItem>
#include <QKeyEvent>
#include<QLabel>
#include <QTimer>

namespace Ui {
class Lushanhu;
}

class Lushanhu : public QWidget
{
    Q_OBJECT

public:
    explicit Lushanhu(QWidget *parent = nullptr);
    ~Lushanhu();

public slots:
    void restartGame();


signals:
    void backToMap();

protected:
    void mousePressEvent(QMouseEvent *event) override;


private slots:
    void updateGame();
    void gameOver();
    void returnToMap();

private:
    void setupScene();
    void spawnPipes();
    void spawnPowerUp();
    void checkCollisions();
    bool isCollidingWithPipes();
    void charAnimations();
    void cleanupScene();
    void cleanupTimer() {
        if (gameTimer) {
            gameTimer->stop();
            disconnect(gameTimer, nullptr, this, nullptr);
            gameTimer->deleteLater();
            gameTimer = nullptr;
        }
    }

    Ui::Lushanhu *ui;
    QGraphicsScene *scene;
    QGraphicsPixmapItem *felyne;
    QGraphicsPixmapItem *luBackground;
    QGraphicsPixmapItem *luBackground1;

    QList<QGraphicsItem*> pipes;//障碍物管道
    QList<QGraphicsItem*> powerUps;//障碍物管道
    QGraphicsPixmapItem *powerUp = nullptr;
    QTimer *gameTimer;
    QLabel *scoreLabel;
    qreal v;
    int score = 0;
    bool hasPowerUp = false;

    // 对话框指针
    QDialog *gameOverDialog;

    //障碍物计时器
    qreal obstacleTimer = 0;
    const qreal obstacleInterval = 2.0;

};

#endif // LUSHANHU_H
